package main

import (
	"flag"
	"fmt"
	"github.com/gogf/gf/frame/g"
	"linkable_spider/link"
	"linkable_spider/task_process"
	"linkable_spider/utils"
	"os"
	"os/signal"
)

var gfcfgFile = flag.String("gffile", "config.yml", "the gf config file")
var gfcfgPath = flag.String("gfpath", "./etc", "the gf config file")

func main() {
	// ...
	g.Cfg().SetPath(*gfcfgPath)
	g.Cfg().SetFileName(*gfcfgFile)
	utils.LoadAccountFromExcel()

	taskServer := task_process.StartServer()
	var name string
	fmt.Println("请选择操作： 1. LOADING-LIST 2. DETAIL-LIST 3. EXPORT-EXCEL ")
	fmt.Scanf("%s", &name)

	c := make(chan os.Signal)
	signal.Notify(c)

	if name == "1" {
		//先处理最外层的一级目录 约5995个
		link.GetLinkableList()
	} else if name == "2" {
		//处理下面的目录和详情
		task_process.ProcessSecondList()
	} else if name == "3" {

		link.ExportExcel()
	} else if name == "4" {
		url := "https://linkable.partcommunity.com/3d-cad-models/sso/gad11-%E5%AE%85" +
			"9%E6%98%82%E5%95%86%E5%9F%8E-fa%E5%B7%A5%E5%8E%82%E8%87%AA%E5%8A%A8%E5%8C%96%E9%9B%B6%E4%BB%B6?info=vipdo%2Ffagongchangzidonghua%2Fdaoxiangzhou%2Fgad11%2Fgad11.prj&cwid=1389"
		//link.GetLinkableDetail(url)

		url = "https://linkable.partcommunity.com/3d-cad-models/sso/aad01-22-%E8%BD%AC%E8%BD%B4-%E5%B8%A6%E6%8C%A1%E5%9C%88%E6%A7%BD%E5%9E%8B-%E7%9B%B4%E6%9D%86%E5%9E%8B-d%E5%85%AC%E5%B7%AEg6-%E5%AE%89%E6%98%82%E5%95%86%E5%9F%8E-fa%E5%B7%A5%E5%8E%82%E8%87%AA%E5%8A%A8%E5%8C%96%E9%9B%B6%E4%BB%B6?info=vipdo%2Ffagongchangzidonghua%2Fzhuanzhou%2Faad01%2Faad01.prj&cwid=7084"

		url = "https://linkable.partcommunity.com/3d-cad-models/sso/uz%E7%B3%BB%E5%88%97%E5%8F%8C%E8%86%9C%E7%89%87-uz%E7%B3%BB%E5%88%97%E5%8F%8C%E8%86%9C%E7%89%87-%E5%BE%B7%E8%BF%88%E6%9C%BA%E5%99%A8%E4%BA%BA?info=dmrobot%2Fmodule-parts%2Fcoupling%2Fuz_series_double_diaphragm_asmtab.prj&cwid=8564"

		//测试获取2D图纸
		url = "https://linkable.partcommunity.com/3d-cad-models/sso/shr-14c-cw-high-performance-rubber-coupling-%E6%A0%AA-%E6%88%90%E4%B8%80%E6%9C%BA%E5%B7%A5?info=sungil%2Fcoupling%2Fshr%2Fshr-c%2Fshr-14c.prj&cwid=5975"

		link.GetDetail(url)

	} else if name == "5" {
		link.TestSvg()
	} else if name == "6" {

	} else {
		fmt.Println("输入错误")
	}

	var name1 string
	fmt.Println("程序运行结束，按任意键退出")
	fmt.Scanf("%s", &name1)
	taskServer.Stop()

}
